<?php
import('Common.Extend.Category', APP_PATH, '.class.php');
class menuAction extends Action
{
    public function index()
    {
        $this->display();
    }

    //menu表操作
    public function menuadd()
    {
        $menu = M("menu");
        $menudata=$menu->select();
        $this->menulist=$menudata;
        $this->display();

    }

    public function menuaddsave()
    {
        header("Content-Type:text/html;charset=utf-8");
        $menu = D("menu");
        $data=$menu->create();
        $data["name"] = I("post.name", "");
        $data["parentid"] = I("post.parentid", 0);
        $data["syslink"] = I("post.syslink", "");
        $data["desorder"] = I("post.desorder", 0);
        $id = $menu->add();
        if ($id) {
            $this->assign("jumpUrl", U("menu/menuadmin"));
            $this->success("添加成功");
        } else {
            $this->error("添加失败");
        }


    }



    public function menuadmin()
    {
        $cat = new Category('menu', array('id', 'parentid', 'name'));
        $temp = $cat->getList(); //获取分类结构

        /*  dump($temp);
          exit();*/

        $this->assign("list", $temp);
        $this->display();

        /*   $menu = new menuModel();
          import("ORG.Util.Page");
          $list = $menu->order("id desc")->select();
          $this->assign("list", $list);
          $this->display();*/
    }

    public function menuupdate()
    {
        $menu = new menuModel();
        $data = $menu->where("id='{$_GET['id']}'")->find();
        $this->assign("data", $data);
        $menu = M("menu");
        $menudata = $menu->select();
        $this->menulist = $menudata;
        $this->display();
    }

    public function menuupdatesave()
    {

        $menu = new menuModel();
        $data = $menu->create();

        if (!$data) {
            $this->error($menu->getError());
        } else {

            $this->assign("jumpUrl", U("menu/menuadmin"));
            if ($menu->save()) {
                $this->success("修改成功");
            } else {
                $this->error("修改失败");
            }

        }
    }

    public function menucontent()
    {
        $menu = new menuModel();
        $data = $menu->where("id='{$_GET['id']}'")->find();
        $this->assign("data", $data);
        $this->display();
    }

    public function menudel()
    {
        $menu = new menuModel();
        $id=I("get.id",0);
        $this->assign("jumpUrl", U("menu/menuadmin"));
        if (!$menu->delete($id)) {
            $this->error("删除失败");
        } else {
            $this->success("删除成功");
        }
    }

    public function _empty()
    {
        //空操作
        $this->error("您访问的页面不存在！");
    }

}

?>